package com.googlecode.c4e.scm;

import org.eclipse.core.runtime.IAdapterFactory;
import org.maven.ide.eclipse.scm.ScmUrl;

import com.googlecode.c4e.api.model.Project;

/**
 * Adopting {@link Project} to {@link ScmUrl}.
 * 
 * @author Tomasz Pik
 */
public class C4EScmUrlAdapterFactory implements IAdapterFactory {

	@SuppressWarnings("unchecked")
	private static final Class[] ADAPTER_TYPES = new Class[] { ScmUrl.class };

	@SuppressWarnings("unchecked")
	public Class[] getAdapterList() {
		return ADAPTER_TYPES;
	}

	@SuppressWarnings("unchecked")
	public Object getAdapter(Object adaptable, Class adapterType) {
		if (ScmUrl.class.equals(adapterType)) {
			if (adaptable instanceof Project) {
				Project project = (Project) adaptable;
				if (project.getScmUrl() != null) {
					return new ScmUrl(project.getScmUrl());
				}
			}
		}
		return null;
	}
}